
func (m *default{{.upperStartCamelObject}}Model) formatPrimary(primary interface{}) string {
	return fmt.Sprintf("%s%v", {{.primaryKeyLeft}}, primary)
}

func (m *default{{.upperStartCamelObject}}Model) queryPrimary(conn *gorm.DB, v, primary interface{}) error {
	return conn.Model(&{{.upperStartCamelObject}}{}).Where("{{.originalPrimaryField}} = ?", primary).Take(v).Error
}

func (m *default{{.upperStartCamelObject}}Model) QueryByKeyword(ctx context.Context, data *{{.upperStartCamelObject}}Keyword) (sys []*{{.upperStartCamelObject}}, total int64, err error) {
    resp :=make([]*{{.upperStartCamelObject}},0)
    var count int64
    err = m.QueryNoCacheCtx(ctx, &resp, func(conn *gorm.DB, v interface{}) error {
        conn.Model(&{{.upperStartCamelObject}}{}).Scopes(base.ParseRequestConditionNoPaging(*data)).Order("last_update_time DESC").Count(&count)
        return conn.Scopes(base.ParseRequestCondition(*data)).Order("last_update_time DESC").Find(&resp).Error
    })
	if err != nil {
        return nil, count, err
    }
    return resp, count, err
}

func (m *default{{.upperStartCamelObject}}Model) FindAll(ctx context.Context) ([]*{{.upperStartCamelObject}}, error) {

	var resp []*{{.upperStartCamelObject}}
	err := m.QueryNoCacheCtx(ctx, &resp, func(conn *gorm.DB, v interface{}) error {
		return conn.Find(&resp).Error
	})
	switch err {
	case nil:
		return resp, nil
	case gormc.ErrNotFound:
		return nil, ErrNotFound
	default:
		return nil, err
	}
}

func (m *default{{.upperStartCamelObject}}Model) FindAllByIds(ctx context.Context, ids []uint) ([]*{{.upperStartCamelObject}}, error) {

	var resp []*{{.upperStartCamelObject}}
	err := m.QueryNoCacheCtx(ctx, &resp, func(conn *gorm.DB, v interface{}) error {
		return conn.Find(&resp,ids).Error
	})
	switch err {
	case nil:
		return resp, nil
	case gormc.ErrNotFound:
		return nil, ErrNotFound
	default:
		return nil, err
	}
}
